package com.analysis.apresunday.controller;

import com.analysis.apresunday.config.R;
import com.analysis.apresunday.entity.po.EmpData;
import com.analysis.apresunday.entity.dto.EmpDataPageDTO;
import com.analysis.apresunday.service.EmpDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/empInfo")
@CrossOrigin
@Slf4j
@Tag(name = "岗位数据")
public class EmpDataController {
    @Resource
    EmpDataService empDataService;

    @Operation(summary = "获取所有岗位数据")
    @GetMapping("/getList")
    public List<EmpData> getList(){
        return empDataService.list();
    }

    @Operation(summary = "分页获取岗位数据")
    @PostMapping("/getEmpDataPage")
    public R getUserOrderPage(@RequestBody EmpDataPageDTO req, HttpServletRequest request) {
        log.info("getUserOrderPage:" + req);
        return R.ok().data("empDataPage",empDataService.getPageList(req,request));
    }

    @Operation(summary = "生成获取json的url")
    @GetMapping("/getUrl/{keyword}")
    public R getUrl(@PathVariable String keyword) {
        return R.ok().data("empUrl",empDataService.getEmpUrl(keyword));
    }

    @Operation(summary = "自动爬取数据")
    @GetMapping("/crawlData/{keyword}")
    public R autoCrawlScript(@PathVariable String keyword) {
        return empDataService.executeAutoCrawlScript(keyword) ? R.ok() : R.error();
    }

}
